package com.nvshen.zhangmeiying.utils;

import java.util.Calendar;

/**
 * Created by wxc on 14-9-16.
 */
public class TimeUtils {
    /**
     * 距离当前时间
     * @param t 单位秒
     * @return
     */
    public static String parseTime(int t){
        long time = System.currentTimeMillis()/1000 - t;
        long minute = (long) Math.ceil(time / 60);// 分钟前

        long hour = (long) Math.ceil(time / 60 / 60);// 小时

        long day = (long) Math.ceil(time / 24 / 60 / 60);// 天前

        String result;
        if (day - 1 >= 0) {
            result = day + "天前";
        } else if (hour - 1 >= 0) {
            result = hour + "小时前";
        } else if (minute - 1 >= 0) {
            result = minute + "分钟前";
        } else {
            result = "刚刚";
        }
        return result;
    }

    public static int getPassedMinutes(int newItem,int oldItem)
    {
        return (int) ((newItem - oldItem) / 60);
    }

    public static String getDisplayTime(int time)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(((long)time) * 1000);
        StringBuilder builder = new StringBuilder();
        builder.append(calendar.get(Calendar.YEAR)).append("-").append(String.format("%02d", calendar.get(Calendar.MONTH) + 1)).append("-").append(String.format("%02d", calendar.get(Calendar.DATE))).append(" ").append(String.format("%02d", calendar.get(Calendar.HOUR_OF_DAY))).append(":").append(String.format("%02d", calendar.get(Calendar.MINUTE)));
        return builder.toString();
    }
}
